package com.xphuong.newskios;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.xphuong.adapter.NewsPaperListAdapter;
import com.xphuong.model.NewsPaper;
import com.xphuong.newskios.util.Util;

public class NewsPaperActivity extends Activity implements OnItemClickListener {

	private Context mContext;
	private NewsPaperListAdapter mAdapter;

	private String[] newsPaper = {};
	private ListView mNewsPaperLst;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mContext = this;
		loadView();
	}

	private void loadView() {
		setContentView(R.layout.activity_newspaper);

		newsPaper = mContext.getResources().getStringArray(
				R.array.newspaper_title_array);
		mAdapter = new NewsPaperListAdapter(mContext, newsPaper);

		mNewsPaperLst = (ListView) findViewById(R.id.newspaper_list);
		mNewsPaperLst.setOnItemClickListener(this);
		mNewsPaperLst.setAdapter(mAdapter);
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int position,
			long arg3) {
		// TODO Auto-generated method stub

		Intent i = new Intent(this, TopicActivity.class);
		i.putExtra(Util.NEWSPAPER_ID, position);
		i.putExtra(Util.NEWSPAPER_TITLE, newsPaper[position]);
		startActivity(i);
	}
}
